package com.bt.lms.ui.action.teaching.plan.utils;

import com.bt.lms.network.msg.packet.ReqMsgPacket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 发送消息
 * @author 李舒淇
 */
public class SendReqMsgPacket {

    /**
     * 发送消息
     * 1.将消息转为字节流
     * 2.发送
     *
     * @param socket  发送的socket
     * @param msgByte   要发送的消息
     * @return
     */
    public static boolean sendReqMsgPacket(Socket socket, byte[] msgByte) {


        //发送
        try {
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write(msgByte);
            outputStream.flush();

            byte[] buffer = new byte[300];
            InputStream in = socket.getInputStream();
            in.read(buffer);

            in.close();
            outputStream.close();
            socket.close();
        } catch (IOException e) {
            //  throw new RuntimeException(e);
        }

        return true;
    }

    }


